package com.rc.saas.tenant.controller.system;

import com.rc.saas.tenant.common.vo.TResponse;
import com.rc.saas.tenant.model.system.RcSetting;
import com.rc.saas.tenant.model.tenant.TenantUser;
import com.rc.saas.tenant.service.system.RcSettingService;
import com.rc.saas.tenant.shiro.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
@RequestMapping("/sys/setting")
public class RcSettingController {
    @Autowired
    private RcSettingService rcSettingService;

    @RequestMapping("/index")
    public String index(Model model) {
        RcSetting info = rcSettingService.selectByPrimaryKey(1l);
        model.addAttribute("setting", info);
        return "/templates/system/setting";
    }


    @ResponseBody
    @RequestMapping("/saveSetting")
    public TResponse saveSetting(RcSetting setting) {
        TenantUser user = ShiroUtils.getSessionUser();
        setting.setLastUpdatedBy(user.getLoginName());
        setting.setLastUpdatedTime(new Date());
        rcSettingService.saveSetting(setting);
        return TResponse.SUCCESS();
    }
}
